src/pages/authors/[...slug].astro (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
--- import AuthorCard from '@/components/AuthorCard.astro' import BlogCard from '@/components/BlogCard.astro' import Breadcrumbs from '@/components/Breadcrumbs.astro' import Container from '@/components/Container.astro' import Layout from '@/layouts/Layout.astro' import { type CollectionEntry, getCollection } from 'astro:content' export async function getStaticPaths() { const authors = await getCollection('authors') return authors.map((author) => ({ params: { slug: author.slug }, props: { author }, })) } type Props = { author: CollectionEntry<'authors'> } const { author } = Astro.props const allPosts = await getCollection('blog') const authorPosts = allPosts .filter((post) => { return post.data.authors && post.data.authors.includes(author.slug) }) .sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf()) --- <Layout title={`${author.data.name} (Author)`} description={author.data.bio || `Profile of ${author.data.name}.`} > <Container class="flex flex-col gap-y-6"> <Breadcrumbs items={[ { href: '/authors', label: 'Authors', icon: 'lucide:users' }, { label: author.data.name, icon: 'lucide:user' }, ]} /> <section> <AuthorCard author={author} linkDisabled /> </section> <section class="flex flex-col gap-y-4"> <h2 class="text-2xl font-semibold">Posts by {author.data.name}</h2> { authorPosts.length > 0 ? ( <ul class="not-prose flex flex-col gap-4"> {authorPosts.map((post) => ( <li> <BlogCard entry={post} /> </li> ))} </ul> ) : ( <p class="text-muted-foreground"> No posts available from this author. </p> ) } </section> </Container> </Layout> |